package com.mapreduce;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class Sort extends WritableComparator {
    public Sort(){
        // 初始化比较器
        super(Text.class,true);
    }
    // 设置比较规则
    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        Text year1 = (Text) a;
        Text year2 = (Text) b;
        // year1比year2小的时候，compareTo返回-1，
        // year2就要放到year1的后面
        // year1比year2大的时候，compareTo返回1
        // year2就要放到year1的前面
        return -year1.compareTo(year2);
    }

    public static void main(String[] args) {
        String year1 = "2000";
        String year2 = "2000";
        System.out.println(year1.compareTo(year2));
    }
}

